package com.nhjf.service.impl.teachers;

import java.util.Date;

import org.apache.commons.lang.StringUtils;
import org.hibernate.FetchMode;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.nhjf.dao.student.StudentDao;
import com.nhjf.dao.system.UserDao;
import com.nhjf.dao.teachers.ReviewPaintingDao;
import com.nhjf.model.student.Student;
import com.nhjf.model.system.User;
import com.nhjf.model.teachers.ReviewPainting;
import com.nhjf.model.teachers.Teacher;
import com.nhjf.pojo.dto.result.ServiceResultDto;
import com.nhjf.pojo.qo.Personalinformation.PersonalinformationQo;
import com.nhjf.pojo.qo.studnet.StudentQo;
import com.nhjf.pojo.qo.system.UserQo;
import com.nhjf.pojo.qo.teachers.ReviewPaintingQo;
import com.nhjf.service.impl.BaseServiceImpl;
import com.nhjf.service.teachers.ReviewPaintingService;

@Transactional
@Service("reviewPaintingService")
public class ReviewPaintingServiceImpl extends BaseServiceImpl<ReviewPainting, ReviewPaintingQo, ReviewPaintingDao> implements ReviewPaintingService{

	@Autowired
	private ReviewPaintingDao reviewPaintingDao;
	@Autowired
	private StudentDao studentDao;
	@Autowired
	private UserDao userDao;
	
	@Override
	protected ReviewPaintingDao getDao() {
		// TODO Auto-generated method stub
		return reviewPaintingDao;
	}

	@Override
	public ServiceResultDto createReviewPainting(String artPicturesUrl, String artName, int width, int height, Long userId,
			Long teacherId, Long typeOne, Long typeTwo) {
		// TODO Auto-generated method stub
		
		  ServiceResultDto resultDto = new ServiceResultDto();
		  ReviewPainting reviewPainting=new ReviewPainting();
		  if(artPicturesUrl==null) {
		      resultDto.setSuccess(false);
		      resultDto.setResultMessage("artPicturesUrlnull");
		  }else {
			  reviewPainting.setNotchangedURL(artPicturesUrl);
		  }
		  if(artName==null) {
			  resultDto.setSuccess(false);
		      resultDto.setResultMessage("artNamenull");
		  }else {
			  reviewPainting.setIntroduce(artName);
		  }
		  if(userId==null) {
			  resultDto.setSuccess(false);
		      resultDto.setResultMessage("userIdnull");
		  }else {
			  UserQo userQo=new UserQo();
			  userQo.setUserId(userId);
			  User user=userDao.queryUnique(userQo);
			  User user1=new User();
			  
			  user1.setId(user.getId());
			  reviewPainting.setUser(user1);
		  }
		  if(teacherId==null) {
			  resultDto.setSuccess(false);
		      resultDto.setResultMessage("teacherIdnull");
		  }else {
			  Teacher teacher=new Teacher();
			  teacher.setId(teacherId);
			  reviewPainting.setTeacher(teacher);
			  
		  }
		  if(typeOne==null) {
			  resultDto.setSuccess(false);
		      resultDto.setResultMessage("typeOnenull");
		  }else {
			  reviewPainting.setTypeOne(typeOne);
		  }
		  if(typeTwo==null) {
			  resultDto.setSuccess(false);
		      resultDto.setResultMessage("typeTwonull");
		  }else {
			  reviewPainting.setTypeTwo(typeTwo);
		  }
		  reviewPainting.setHeight(height);
		  reviewPainting.setStatus(1);
		  reviewPainting.setWidth(width);
		
		  
		  reviewPainting.setReleasetime(new Date());
		  reviewPaintingDao.save(reviewPainting);
	      resultDto.setSuccess(true);
	      resultDto.setResultMessage("创建成功");
	      return resultDto;

	}


}